package com.lovo.dao.impl;

import com.lovo.bean.Room;
import com.lovo.dao.BaseDAO;
import com.lovo.dao.RoomDAO;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoomDAOImpl extends BaseDAO implements RoomDAO {
    @Override
    public List<Room> find() {
        PreparedStatement statement = null;
        ResultSet result = null;
        List list = new ArrayList();
        try {
            String sql = "select * from t_room ";
            statement = con.prepareStatement(sql);
            result = statement.executeQuery();
            while(result.next()){
                list.add(fillRoom(result));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            this.close(con,statement,result);
        }
        return list;
    }
    private Room fillRoom(ResultSet rs) throws SQLException {
        Room room = new Room();
        room.setId(rs.getInt("r_id"));
        room.setAddr(rs.getString("r_addr"));
        return room;
    }
}
